from celery import Celery

# 一、加载django配置环境
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "luffy_api.settings.dev")

broker = 'redis://:foobared@1.116.131.59:8888/14'  # 消息中间件 redis
backend = 'redis://:foobared@1.116.131.59:8888/15'  # 结果存储 redis

app = Celery(__name__, broker=broker, backend=backend,
             include=['celery_task.banner_task', 'celery_task.sms_task']
             )

### 3 定时任务要写在这里
# 时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False

# 任务的定时配置
from datetime import timedelta
from celery.schedules import crontab

app.conf.beat_schedule = {
    'update_banner': {
        'task': 'celery_task.banner_task.update_banner',
        'schedule': timedelta(seconds=5),
        'args': (),
    }
}
